BOOL BLEND(PBITMAP lpbDst, PBITMAPEX lpbSrc, BYTE alpha)
{
    LPBYTE lpScanSrc = (LPBYTE)lpbSrc->bmBits;
    LPBYTE lpScanDst = (LPBYTE)lpbDst->bmBits;
    DWORD width = lpbDst->bmWidth;
    DWORD dwAlpha = (DWORD)alpha + 1;
    __m64 mAlpha = _m_from_int(dwAlpha);
    mAlpha = _m_punpcklwd(mAlpha, mAlpha);
    mAlpha = _m_punpckldq(mAlpha, mAlpha);
    for (int j = lpbDst->bmHeight; j > 0; --j)
    {
        PBYTE lpPixelSrc = lpScanSrc;
        LPDWORD lpPixelDst = (LPDWORD)lpScanDst;
        int i = width >> 1;
        while (i--)
        {
            __m64 src = GET2PIXEL(lpbSrc, lpPixelSrc);
            BLEND2PIXEL(*((__m64*)lpPixelDst), src, mAlpha);
            lpPixelSrc += (PIXEL_BYTES << 1);
            lpPixelDst += 2;
        }
        if (width & 1)
        {
            xARGB src = GETPIXEL(lpbSrc, lpPixelSrc);
            BLENDPIXEL(*lpPixelDst, src.argb, mAlpha);
        }
        lpScanSrc += lpbSrc->bmWidthBytes;
        lpScanDst += lpbDst->bmWidthBytes;
    }
    _m_empty();
    return TRUE;
}

BOOL BLENDSTRETCH(PBITMAP lpbDst, PBITMAPEX lpbSrc, BYTE alpha)
{
    LPBYTE lpScanDst = (LPBYTE)lpbDst->bmBits;
    DWORD xrIntFloat16 = (lpbSrc->bmWidth << 16) / lpbDst->bmWidth;
    DWORD yrIntFloat16 = (lpbSrc->bmHeight << 16) / lpbDst->bmHeight;
    DWORD srcy16 = 0;
    DWORD width = lpbDst->bmWidth;
    DWORD dwAlpha = (DWORD)alpha + 1;
    __m64 mAlpha = _m_from_int(dwAlpha);
    mAlpha = _m_punpcklwd(mAlpha, mAlpha);
    mAlpha = _m_punpckldq(mAlpha, mAlpha);
    for (int j = 0; j < lpbDst->bmHeight; ++j)
    {
        PBYTE lpScanSrc = (LPBYTE)lpbSrc->bmBits + lpbSrc->bmWidthBytes * (srcy16 >> 16);
        DWORD srcx16 = 0;
        LPDWORD lpPixelDst = (LPDWORD)lpScanDst;
        int i = width >> 1;
        while (i--)
        {
            __m64 src = _m_from_int(GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES).argb);
            srcx16 += xrIntFloat16;
            src =_m_punpckldq(src, _m_from_int(GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES).argb));
            srcx16 += xrIntFloat16;
            BLEND2PIXEL(*((__m64*)lpPixelDst), src, mAlpha);
            lpPixelDst += 2;
        }
        if (width & 1)
        {
            xARGB src = GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES);
            BLENDPIXEL(*lpPixelDst, src.argb, mAlpha);
        }
        srcy16 += yrIntFloat16;
        lpScanDst += lpbDst->bmWidthBytes;
    }
    _m_empty();
    return TRUE;
}

BOOL BLENDSTRETCH(PBITMAP lpbDst, PBITMAPEX lpbSrc, BYTE alpha, LPCSIZE lpszDst, LPCRECT lprcClipped)
{
    LPBYTE lpScanDst = (LPBYTE)lpbDst->bmBits;
    DWORD xrIntFloat16 = (lpbSrc->bmWidth << 16) / lpszDst->cx;
    DWORD yrIntFloat16 = (lpbSrc->bmHeight << 16) / lpszDst->cy;
    DWORD srcy16 = (DWORD)(lprcClipped->top * yrIntFloat16);
    DWORD width = lpbDst->bmWidth;
    DWORD dwAlpha = (DWORD)alpha + 1;
    __m64 mAlpha = _m_from_int(dwAlpha);
    mAlpha = _m_punpcklwd(mAlpha, mAlpha);
    mAlpha = _m_punpckldq(mAlpha, mAlpha);
    for (int j = 0; j < lpbDst->bmHeight; ++j)
    {
        PBYTE lpScanSrc = (LPBYTE)lpbSrc->bmBits + lpbSrc->bmWidthBytes * (srcy16 >> 16);
        DWORD srcx16 = (DWORD)(lprcClipped->left * xrIntFloat16);
        LPDWORD lpPixelDst = (LPDWORD)lpScanDst;
        int i = width >> 1;
        while (i--)
        {
            __m64 src = _m_from_int(GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES).argb);
            srcx16 += xrIntFloat16;
            src =_m_punpckldq(src, _m_from_int(GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES).argb));
            srcx16 += xrIntFloat16;
            BLEND2PIXEL(*((__m64*)lpPixelDst), src, mAlpha);
            lpPixelDst += 2;
        }
        if (width & 1)
        {
            xARGB src = GETPIXEL(lpbSrc, lpScanSrc + (srcx16 >> 16) * PIXEL_BYTES);
            BLENDPIXEL(*lpPixelDst, src.argb, mAlpha);
        }
        srcy16 += yrIntFloat16;
        lpScanDst += lpbDst->bmWidthBytes;
    }
    _m_empty();
    return TRUE;
}